home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 14 / opusgraf.awk < prev    next >
Text File  |  1989-02-20  |  2KB  |  71 lines

  1. #
  2. # opusgraf.awk - makes a histogram of Opus BBS caller usage 
  3. #
  4.  
  5. BEGIN { # get the bbs name from the command line
  6.         bbs_name = ARGV[ARGC - 1]
  7.       
  8.     # then null it out so it wont be interpreted as a file name
  9.         ARGV[ARGC - 1] = ""
  10.  
  11.     # initialize an array with entries for each half-hour
  12.         # period
  13.           for(hour = 0;hour < 24;hour++) {
  14.               hour = (length(hour) < 2) ? ("0" hour) : hour
  15.               for(min = "00";min < 60;min += 30)
  16.            humans[hour ":" min] = 0;
  17.               }
  18.             }
  19.  
  20. # we're only interested in callers
  21. /calling/ {
  22.            # some log entries have a blank first field, so
  23.            # we have to compensate
  24.                if ($4 ~ /:/)   
  25.                     fld = 4
  26.                  else
  27.                 fld = 3
  28.  
  29.      # save the first and last dates
  30.          if (startdate == "")
  31.             startdate = $(fld - 1) " " $(fld - 2)
  32.              else
  33.             enddate = $(fld - 1) " " $(fld - 2)
  34.  
  35.             # process the hour entry, remove ":" if necessary and
  36.             # pad with 0's 
  37.                 hour = substr($fld,1,2)
  38.                      if (sub(":","",hour))
  39.                 hour = (length(hour) < 2) ? ("0" hour) : hour
  40.  
  41.             # process the minutes entry, rounding off at half-hour intervals
  42.                 min  = substr($fld,4,2)
  43.                     if (min < 30)
  44.                        min = 0
  45.                         else
  46.                        min = 30
  47.  
  48.             # assemble the index string 
  49.                 timestring = hour ":" ((min == 0) ? "00" : min)
  50.                          
  51.             # increment the value
  52.                 humans[timestring]++
  53.                        }
  54.  
  55.  
  56. END { 
  57.        # put the name of the BBS on the command line
  58.              printf("Stats for %s from %s to %s\n\n",bbs_name,startdate,enddate)
  59.  
  60.        # generate the histogram
  61.          for(time in humans) {
  62.              printf("%s\t%s\n",time,rep(humans[time],"*"))
  63.          }
  64.     }
  65.  
  66. function rep(n,s,   t) {
  67.  while(n-- > 0)
  68.     t = t s
  69.  return t
  70. }
  71.